﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HRC.Library.ContextFoundation;
using Lehnet.BusinessLayer;
using Lehnet.BusinessLayer.Interfaces;
using Lehnet.Models;


namespace Lehnet.WebUI.Controllers
{
   [CustomAttributes.PersonelAuthorize]
    public class PersonelController : Controller
    {
        //
        // GET: /Personel/
        public ActionResult Index()
        {
            return View();
        }

        public JsonResult GetAllPersonelAjax()
        {
            var pb = ProxyHelper<PersonelBusiness, IPersonelBusiness>.Instance.AddOrGet();
            List<Personel> personelList = pb.LoadAll();

            JsonResult result = Json(personelList);
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return result;
        }

        [HttpPost]
        public PartialViewResult Create(Models.Personel personel)
        {
            var pb = ProxyHelper<PersonelBusiness, IPersonelBusiness>.Instance.AddOrGet();
            pb.SaveOrUpdate(personel);
            return PartialView();
        }
        public PartialViewResult Create(int? Id)
        {
            var m = new Personel();
            if (Id != null)
            {
                var pb = ProxyHelper<PersonelBusiness, IPersonelBusiness>.Instance.AddOrGet();
                m = pb.LoadPersonelById((int)Id);
            }
            return PartialView(m);
        }
        public JsonResult DeletePersonelAjax(int personelId)
        {
            var ib = ProxyHelper<PersonelBusiness, IPersonelBusiness>.Instance.AddOrGet();
            ib.Delete(personelId);

            JsonResult result = Json("Succsess");
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return result;
        }
    }
}
